﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;

namespace Tomahawk.Runtime.Rendering.Particles
{
    public class ParticleSourceCircle : ParticleSource
    {
        #region Serializable Properties
        [XmlElement("InnerRadius")]
        public float innerRadius = 0.0f;
        [XmlElement("OuterRadius")]
        public float outerRadius = 0.0f;
        [XmlElement("Velocity")]
        public Vector3 velocity = Vector3.Zero;
        #endregion

        public override Vector3 GenerateParticlePosition(ref Matrix worldMatrix)
        {
            double angle = ParticleSystem.Random.NextDouble() * Math.PI * 2;
            double radius = innerRadius + ParticleSystem.Random.NextDouble() * (outerRadius - innerRadius);

            float x = (float)Math.Cos(angle);
            float z = (float)Math.Sin(angle);

            Vector3 position = Vector3.Zero;
            position.X = x * (float) radius;
            position.Z = z * (float) radius;

            return Vector3.Transform(position, worldMatrix);
        }

        public override Vector3 GenerateParticleVelocity(ref Matrix worldMatrix)
        {
            return Vector3.TransformNormal(AddNoiseToVelocity(ref velocity), worldMatrix);
        }
    }
}
